'''
Company: TWL
Author: xue jian
Email: xuejian@kanzhun.com
Date: 2020-08-06 14:29:25
'''
import os
import sys
import json
sys.path.append(os.path.abspath(os.path.join(os.path.dirname('__file__'), os.path.pardir)))

import thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from recallapi.GeekRecallApiThrift import Client
from recallapi.ttypes import *
import uuid
from cityhash import *



def recall_boss(host, bossid, jobid, city, position, applyJobType):
    try:
        port = 10066
        tsocket = TSocket.TSocket(host, port)
        transport = TTransport.TFramedTransport(tsocket)
        protocol = TBinaryProtocol.TBinaryProtocol(transport)
        client = Client(protocol)

        transport.open()
        
        uuid = str(uuid.uuid4())
        # print(type(uuid))
        extbyte = {}
        extbyte['applyJobType'] = int(applyJobType).to_bytes(length=4, byteorder='big')
        tGeekRecallReq = TGeekRecallReq(uuid, bossid, jobid, 101010100, 240303, extBytes=extbyte)

        client.recall(tGeekRecallReq)
        
        print(uuid)

        transport.close()
    except thrift.Thrift.TException as ex:
        print(ex.message)


if __name__ == "__main__":
    with open('cityHash.txt') as f:
        lines = f.readlines()
        for line in lines:
            line = line.split('\t')
            val = int(line[1])
            tmp = int(CityHash64(line[0]))
            if tmp != val:
                print('str: {0}, val: {1}, tmp: {2}'.format(line[0], val, tmp))